package com.wdd.atcrowdfunding.manager.service.impl;

import com.wdd.atcrowdfunding.bean.AccountTypeCert;
import com.wdd.atcrowdfunding.bean.Cert;
import com.wdd.atcrowdfunding.bean.MemberCert;
import com.wdd.atcrowdfunding.manager.dao.AccountTypeCertMapper;
import com.wdd.atcrowdfunding.manager.dao.CertMapper;
import com.wdd.atcrowdfunding.manager.service.CertService;
import com.wdd.atcrowdfunding.util.Page;
import com.wdd.atcrowdfunding.vo.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CertServiceImpl implements CertService {

    @Autowired
    private CertMapper certMapper;
    @Autowired
    private AccountTypeCertMapper accountTypeCertMapper;

    @Override
    public Page<Cert> pageQuery(Map<String, Object> paramMap) {
        Page<Cert> certPage = new Page<Cert>((Integer)paramMap.get("pageno"),(Integer)paramMap.get("pagesize"));
        paramMap.put("startIndex", certPage.getStartIndex());
        List<Cert> certs = certMapper.pageQuery(paramMap);
        // 获取数据的总条数
        int count = certMapper.queryCount(paramMap);
        certPage.setDatas(certs);
        certPage.setTotalsize(count);
        return certPage;
    }

    @Override
    public Cert queryById(Integer id) {
        return certMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateCert(Cert cert) {
        return certMapper.updateByPrimaryKey(cert);
    }

    @Override
    public void insertCert(Cert cert) {
        certMapper.insert(cert);
    }

    @Override
    public int deleteCert(Integer id) {
        return certMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int deleteCerts(Data ds) {
        return certMapper.deleteCerts(ds);
    }

    @Override
    public List<Cert> getALLCert() {
        return certMapper.selectByExample(null);
    }

    @Override
    public List<Cert> queryCertByAccttype(String accttype) {
        List<AccountTypeCert> accountTypeCertList = accountTypeCertMapper.queryCertId(accttype);
        List<Cert> certs = certMapper.queryCertByAccttype(accountTypeCertList);
        return certs;
    }

}
